package jxc.servlet.sale;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jxc.data.hibernate.dao.InportDAO;
import jxc.data.hibernate.pojo.Goods;
import jxc.data.hibernate.pojo.Inport;

/**
 * Servlet implementation class ReturnChoose
 */
@WebServlet("/sale/returnChoose")
public class ReturnChoose extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String provider=request.getParameter("pid");
    	String name=request.getParameter("name");
		String gid=request.getParameter("id");
		InportDAO dao=new InportDAO();
		List<Goods> goods=new ArrayList<Goods>();
		if(gid!=null&&gid.length()>0){
			//根据商品编号查找
			Inport inport=dao.getByGoodsProvider(gid, provider);
			if(inport!=null)
				goods.add(inport.getTbGoods());
		}else if(name!=null&&name.length()>0){
			for(Inport inport:dao.getLikeGoodsnameByProvider(name, provider))
				goods.add(inport.getTbGoods());
		}
		request.setAttribute("goods", goods);
		request.getRequestDispatcher("/sale/returnList.jsp").forward(request, response);
	}

}
